<!DOCTYPE html>
<html lang="en">
<#assign ctx=springMacroRequestContext.contextPath/>

<head>
    <title>Holmes</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"/>
    <link rel="stylesheet" href="${ctx}/css/style.css">
    <script src="${ctx}/js/jquery-3.4.1.min.js"></script>
    <script src="${ctx}/js/microlight.js"></script>


</head>

<body>
<header>
    <h1>
        <a href="#">搜搜搜</a>
        <img src="${ctx}/images/holmes_logo-hover.svg" alt="Holmes Logo">
    </h1>
    <p>输入公司code，然后选中想要查看的点击即可.</p>
</header>


<div class="search">
    <label for="search"></label><input type="search" id="search" placeholder="输入股票代码或者公司名字" required>
</div>
<div class="results">

</div>
<span class="separator"></span>

<!--<script src="js/holmes.js"></script>-->
<script>
    $('#search').on('input', function () {
        let keyword = $(this).val();
        let $results = $(".results");
        $results.children().remove();
        if (keyword === '') {
            return
        }
        fetch("${ctx}/rest/seach/" + keyword, {method: 'GET'})
            .then(res => {
                return res.json()
            })
            .then(res => {
                if (res.code === 200) {
                    const list_html = res.data.map((item) => ' <blockquote onclick="to_stock(\'' + item._id + '\',\'' + item.stockCode + '\')">'
                        + item.name + '<br>' +
                        '<cite>&nbsp;' + item.stockCode + '.' + item.areaCode + '</cite>'
                        + ' </blockquote>');
                    $results.html(list_html);

                } else {
                    console.log("请求失败！！！！！")
                    console.log(res.code);
                    console.log(res.message);
                }
            })
    });

    function to_stock(id, stock_code) {
        window.location.href = "${ctx}/stock?id=" + id + "&stockCode=" + stock_code;
    }

</script>
</body>

</html>
